//
//  MCActionDetailApi.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/26.
//

import Foundation
import Moya

enum MCActionDetailApi {
    //获取推荐器械
    case getRecommanInstrument(current:Int,zhName:String)
    ///器械详情页
    case getInstrumentDetail(ids:String)
    //动作详情页
    case getActionDetail(ids:String)
    //根据器械详情获取动作
    case getInstrumentInfoActionDetail(current:Int?,instrumentIds:String?)
    //推荐器械列表
    case getInstrumentRecommandDetail(current:Int?,zhName:String?)
}

extension MCActionDetailApi:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .getRecommanInstrument:
            return "api/app/action/getInstrumentPage"
        case .getInstrumentDetail:
            return "api/app/action/instrumentDetail"
        case .getActionDetail:
            return "api/app/action/actionDetail"
        case .getInstrumentInfoActionDetail:
            return "api/app/action/getActionPage"
        case .getInstrumentRecommandDetail:
            return "api/app/action/getInstrumentPage"
        }
    }
    var method:Moya.Method {
        switch self {
        case .getRecommanInstrument:
            return .get
        case .getInstrumentDetail:
            return .get
        case .getActionDetail:
            return .get
        case .getInstrumentInfoActionDetail:
            return .get
        case .getInstrumentRecommandDetail:
            return .get
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case let .getRecommanInstrument(current, zhName):
            return .requestParameters(parameters: ["current":current,"size":20,"zhName":zhName], encoding: URLEncoding.default)
        case let .getInstrumentDetail(ids):
            return .requestParameters(parameters: ["id":ids], encoding: URLEncoding.default)
        case let .getActionDetail(ids):
            return .requestParameters(parameters: ["id":ids], encoding: URLEncoding.default)
        
        case let .getInstrumentInfoActionDetail(current, instrumentIds):
            return .requestParameters(parameters: ["current":current ?? -1,"instrumentIds":instrumentIds ?? "","size":20], encoding: URLEncoding.default)
        case let .getInstrumentRecommandDetail(current, zhName):
            return .requestParameters(parameters: ["current":current ?? -1,"zhName":zhName ?? "","size":20], encoding: URLEncoding.default)
        }
    }
    
    var headers: [String : String]? {
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        return [tokenName:tokenValue]
    }
    
    
}
